// pages/index/liangfang.js
Page({
  data: {
    phone: '',
    ci_rwdid: '',
    ci_DesignerCard: '',
    ci_ClientName: '',
    ca_MeasureDate: '',
    ci_DecorationAddress: '',
    Mobile: '',
    ca_AuditState: 0,
    ca_AuditStateName: ''
  },

  onLoad: function (options) {
    var that = this
    // 拿到缓存数据
    wx.getStorage({
      key: 'phone',
      success: function (res) {
        
        console.log('phone', res.data)
        // if (res.data != '') {
        //   wx.request({
        //     url: 'https://api.wenes.cn/JD/GetClientInfo?Phone=' + res.data,
        //     method: 'GET',
        //     success: function (res) {
        //       console.log(res.data)
        //       that.setData({
        //         table: res.data.Table
        //       })
        //     },
        //   })
        // }
      },
    })
    that.setData({
      ci_rwdid: that.data.ci_rwdid,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('onshow')
    var that = this
    wx.getStorage({
      key: 'phone',
      success: function(res) {
        if (res.data != '') {
          wx.request({
            url: 'https://api.wenes.cn/JD/GetClientInfo?Phone=' + res.data,
            method: 'GET',
            success: function (res) {
              console.log(res)
              if(res.statusCode == 200){
                that.setData({
                  table: res.data.Table
                })
              }else{
              
              }
            },
          })
        }
      },
    })
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this
    wx.getStorage({
      key: 'phone',
      success: function (res) {
        if (res.data != '') {
          wx.request({
            url: 'https://api.wenes.cn/JD/GetClientInfo?Phone=' + res.data,
            method: 'GET',
            success: function (res) {
              console.log(res.data)
              that.setData({
                table: res.data.Table
              })
            },
          })
        }
      },
    })
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
 
  // 跳转到详情页
  measureroom: function (e) {
    console.log(e)
    var that = this
    var id = e.currentTarget.dataset.id
    var state = e.currentTarget.dataset.state
    //判断量房状态，根据量房状态跳转不同界面
    if (state == null) {
      wx.navigateTo({
        // 12-187558 
        url: '../dailiangfang/measureroom?ci_rwdid=' + id,
        success: function (res) {
        },
      })
    } else if (state == 4 || state == 3) {
      wx.navigateTo({
        url: '../yiliangfang/measureroom?ci_rwdid=' + id,
        success: function (res) {
        },
      })
    }

  },

  onReachBottom: function () {
    console.log('onReachBottom')
  },

})